package com.app.utils;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.rules.DateType;

import java.util.Collections;

public class AutoCodeCreateUtil {
    public static void main(String[] args) {
        //配置DataSourceConfig
        DataSourceConfig dataSourceConfig = new DataSourceConfig.Builder(
                "jdbc:mysql://127.0.0.1:3306/pkuku?serverTimezone=UTC",
                "root",
                "root")
                .build();

        //配置全局信息 ： GlobalConfig
        GlobalConfig globalConfig =  new GlobalConfig.Builder()
                .fileOverride() //是否覆盖已有的内容
                .outputDir("C:\\Users\\Yang177\\Desktop\\java后端项目\\yjj2001\\src\\main\\java") //输出到哪里
                .author("杨") //作者是谁
                .enableSwagger()
                .dateType(DateType.TIME_PACK)
                .commentDate("yyyy-MM-dd")
                .build();

        //配置包的信息 : PackageConfig
        PackageConfig packageConfig =  new PackageConfig.Builder()
                .parent("com")
                .moduleName("app")
                .entity("pojo")
                .service("service")
                .serviceImpl("service.impl")
                .mapper("mapper")
                .xml("mapper.xml")
                .controller("ctrl")
                .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "C:\\Users\\Yang177\\Desktop\\java后端项目\\yjj2001\\src\\main\\resources\\mapper"))
                .build();
        //创建执行类
        AutoGenerator generator = new AutoGenerator(dataSourceConfig);
        generator.global(globalConfig);
        generator.packageInfo(packageConfig);
        //调用这个自动生成代码的执行类的执行方法
        generator.execute();
    }
}
